﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.Common;
using Mocola.BLL;
using Mocola.Model;

namespace Mocola.Net.Web.ajax
{
    public partial class UpdateProject : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                MembershipCreateStatus status = new MembershipCreateStatus();
                DbTransaction transaction = Databases.MocolaNet.BeginTransaction(IsolationLevel.ReadCommitted);

                try
                {
                    int ProjectID = Convert.ToInt32(Request.QueryString["id"]);

                    string pXmxz1 = getRequest("Xmxz1");        // 项目类型1
                    string pXmxz2 = getRequest("Xmxz2");        // 项目类型2
                    string pXmxz3 = getRequest("Xmxz3");        // 项目类型3
                    string pXmxzZdy = getRequest("XmxzZdy");    // 项目类型-自定义

                    string pJglx = getRequest("Jglx");          // 结构类型
                    string pXmmc = getRequest("Xmmc");          // 项目名称
                    string pZdh = getRequest("Zdh");            // 宗地号
                    string pDkm = getRequest("Dkm");            // 地块名
                    string pAnming = getRequest("Anming");      // 案名
                    string pCym1 = getRequest("Cym1");          // 曾用名一
                    string pCym2 = getRequest("Cym2");          // 曾用名二
                    string pRdoXmmc = getRequest("nRdoXmmc");   // 名称选项

                    string pKgtime = getRequest("Kgtime") + "-" + getRequest("Kgtime-m") + "-" + getRequest("Kgtime-d");      // 开工时间
                    string pJgtime = getRequest("Jgtime") + "-" + getRequest("Jgtime-m") + "-" + getRequest("Jgtime-d");      // 竣工时间

                    string pXmzt = getRequest("Xmzt");          // 项目状态

                    string pZdmj = getRequest("Zdmj");          // 占地面积
                    string pDsjzmj = getRequest("Dsjzmj");      // 地上建筑面积
                    string pDxjzmj = getRequest("Dxjzmj");      // 地下建筑面积
                    string pZjzmj = getRequest("Zjzmj");        // 总建筑面积
                    string pJrmj = getRequest("Jrmj");          // 计容面积

                    string pXmtzqy = getRequest("Xmtzqy");      // 项目投资企业

                    string pSgdw = getRequest("Sgdw");          // 施工单位
                    string pSjdw = getRequest("Sjdw");          // 设计单位
                    string pJldw = getRequest("Jldw");          // 监理单位

                    string pXmdz = getRequest("Xmdz");          // 项目地址
                    string pBeizhu = getRequest("Beizhu");      // 备注

                    bool bUpdated = Databases.MocolaNet.Update(Moc_ProjectInfo.Moc_Project)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.Name, pXmmc)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.PlaceName, pDkm)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.PlotName, pZdh)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.CaseName, pAnming)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.OldName1, pCym1)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.OldName2, pCym2)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.NameChiose, pRdoXmmc)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.Character1, pXmxz1)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.Character2, pXmxz2)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.Character3, pXmxz3)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.CharacterZdy, pXmxzZdy)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.Structure, pJglx)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.StartTime, pKgtime)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.EndTime, pJgtime)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.State, pXmzt)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.PlaceArea, pZdmj)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.OvergroundArea, pDsjzmj)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.BlewgroundArea, pDxjzmj)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.TotalArea, pZjzmj)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.JrArea, pJrmj)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.Corps, pXmtzqy)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.ConstructUnit, pSgdw)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.DesignUnit, pSjdw)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.IntendanceUnit, pJldw)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.Address, pXmdz)
                                 .AddColumn(Moc_ProjectInfo.Moc_Project.Remark, pBeizhu)
                                 .Where(Moc_ProjectInfo.Moc_Project.ProjectID == ProjectID)
                                 .SetTransaction(transaction)
                                 .Execute() == 1;
                    if (bUpdated)
                    {
                        Response.Write("项目更新成功！");
                        status = MembershipCreateStatus.Success;
                    }
                    else
                    {
                        Response.Write("项目更新失败！");
                        status = MembershipCreateStatus.ProviderError;
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    status = MembershipCreateStatus.ProviderError;
                }
                finally
                {
                    if (status == MembershipCreateStatus.Success)
                        transaction.Commit();
                    else
                        transaction.Rollback();
                    Databases.MocolaNet.CloseConnection(transaction);
                }
            }
        }

        private string getRequest(string pReqID)
        {
            return string.IsNullOrEmpty(Request.Form[pReqID]) ? string.Empty : Request.Form[pReqID].ToString();
        }
    }
}
